<?php
$root = dirname(__FILE__);
$dir = scandir(__DIR__);
$title = '请输入您需要更改的文件后缀:';
echo iconv("UTF-8","gbk//TRANSLIT",$title);
$ex = trim(fgets(STDIN));
$exText = iconv("UTF-8","gbk//TRANSLIT",'您输入需要更改文件格式为:'.$ex);
echo $exText.PHP_EOL;

echo iconv("UTF-8","gbk//TRANSLIT",'您希望将文件格式：'.$ex.' 更改为什么后缀呢：');
$ex2 = trim(fgets(STDIN));
echo iconv("UTF-8","gbk//TRANSLIT",'OK，现在正在将'.$ex.'文件更改为 '.$ex2.'文件，处理中，请等候...').PHP_EOL;
$n =0;
foreach ($dir as &$item){
    $file = $root.DIRECTORY_SEPARATOR.$item;
    $fex = pathinfo($file,PATHINFO_EXTENSION);
    if($item == '.' || $item == '..'){
        continue;
    }
    if ($fex == $ex){
        rename($file,pathinfo($file,PATHINFO_FILENAME).'.'.$ex2);
        $n++;
    }

}
echo iconv("UTF-8","gbk//TRANSLIT",'处理完成，成功更改 '.$n.' 个文件');